var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        });
Object.defineProperty(i, "__esModule", {value: !0});
var r = e("AssetsMap"),
    s = e("BundleNames"),
    c = e("Util"),
    l = e("MatchPlayersView"),
    d = (function (e) {
        function t(o) {
            var n = e.call(this, t.NAME, o) || this;
            return (
                (n._minPlayerCount = 2),
                (n._maxPlayerCount = 4),
                (n._currPlayerCount = 0),
                (n._timeOut = 5),
                (n._isInventedMatch = !1),
                n
            );
        }
        return (
            a(t, e),
            (t.prototype.listNotificationInterests = function () {
                return [];
            }),
            (t.prototype.handleNotification = function (e) {
                e.getName();
            }),
            (t.prototype.onRegister = function () {
                var t = this;
                e.prototype.onRegister.call(this),
                    this.matchPlayersView.node.on(l.default.ON_CLICK_EXIT, this.onClickExit, this),
                    this.matchPlayersView.scheduleOnce(function () {
                        t.simulationMatch(t._currPlayerCount, t._maxPlayerCount, function () {
                            t.matchPlayersView.scheduleOnce(function () {
                                t.onJoinGame();
                            }, 1);
                        });
                    }, 1),
                    this.matchPlayersView.refreshCurrPlayerCount(0, this._maxPlayerCount),
                    (this._currPlayerCount = 0);
            }),
            (t.prototype.onRemove = function () {
                e.prototype.onRemove.call(this),
                    this.matchPlayersView.node.off(l.default.ON_CLICK_EXIT, this.onClickExit, this);
            }),
            (t.prototype.onClickExit = function () {
                this.exit();
            }),
            (t.prototype.exit = function (e) {
                void 0 === e && (e = !0), e && this.matchPlayersView.closeView(!0);
            }),
            (t.prototype.simulationMatch = function (e, t, o) {
                var n = this;
                this._isInventedMatch ||
                    ((this._isInventedMatch = !0),
                    this.matchPlayersView.refreshCurrPlayerCount(e, t),
                    this.matchPlayersView.scheduleOnce(function i() {
                        e++,
                            (n._currPlayerCount = e),
                            n.matchPlayersView.refreshCurrPlayerCount(e, t),
                            e < t
                                ? n.matchPlayersView.scheduleOnce(function () {
                                      i();
                                  }, c.default.randomFrom(5, 15) / 30)
                                : o && o();
                    }, c.default.randomFrom(5, 20) / 10));
            }),
            Object.defineProperty(t.prototype, "matchPlayersView", {
                get: function () {
                    return this.viewComponent;
                },
                enumerable: !1,
                configurable: !0
            }),
            (t.prototype.onJoinGame = function () {
                game.UIManager.instance.showLoadResView([s.default.Game], [s.default.Game], function () {
                    game.UIManager.instance.replaceModuleView(
                        s.default.Game,
                        r.default.GameBundle.prefabs.assetsList.GameModuleView,
                        {}
                    );
                });
            }),
            (t.NAME = "MatchPlayersViewMediator"),
            t
        );
    })(puremvc.Mediator);
i.default = d;
